package cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDetail;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDetail.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyReservePlainDetail.BizEmergencyReservePlainDetailDO;
import cn.iocoder.yudao.module.biz.convert.emergencyReservePlainDetail.BizEmergencyReservePlainDetailConvert;
import cn.iocoder.yudao.module.biz.service.emergencyReservePlainDetail.BizEmergencyReservePlainDetailService;

@Api(tags = "管理后台 - 预案详情")
@RestController
@RequestMapping("/biz/emergency-reserve-plain-detail")
@Validated
public class BizEmergencyReservePlainDetailController {

    @Resource
    private BizEmergencyReservePlainDetailService emergencyReservePlainDetailService;

    @PostMapping("/create")
    @ApiOperation("创建预案详情")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-detail:create')")
    public CommonResult<String> createEmergencyReservePlainDetail(@Valid @RequestBody BizEmergencyReservePlainDetailCreateReqVO createReqVO) {
        return success(emergencyReservePlainDetailService.createEmergencyReservePlainDetail(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新预案详情")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-detail:update')")
    public CommonResult<Boolean> updateEmergencyReservePlainDetail(@Valid @RequestBody BizEmergencyReservePlainDetailUpdateReqVO updateReqVO) {
        emergencyReservePlainDetailService.updateEmergencyReservePlainDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除预案详情")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-detail:delete')")
    public CommonResult<Boolean> deleteEmergencyReservePlainDetail(@RequestParam("id") String id) {
        emergencyReservePlainDetailService.deleteEmergencyReservePlainDetail(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得预案详情")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-detail:query')")
    public CommonResult<BizEmergencyReservePlainDetailRespVO> getEmergencyReservePlainDetail(@RequestParam("id") String id) {
        BizEmergencyReservePlainDetailDO emergencyReservePlainDetail = emergencyReservePlainDetailService.getEmergencyReservePlainDetail(id);
        return success(BizEmergencyReservePlainDetailConvert.INSTANCE.convert(emergencyReservePlainDetail));
    }

    @GetMapping("/list")
    @ApiOperation("获得预案详情列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-detail:query')")
    public CommonResult<List<BizEmergencyReservePlainDetailRespVO>> getEmergencyReservePlainDetailList(@RequestParam("ids") Collection<String> ids) {
        List<BizEmergencyReservePlainDetailDO> list = emergencyReservePlainDetailService.getEmergencyReservePlainDetailList(ids);
        return success(BizEmergencyReservePlainDetailConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得预案详情分页")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-detail:query')")
    public CommonResult<PageResult<BizEmergencyReservePlainDetailRespVO>> getEmergencyReservePlainDetailPage(@Valid BizEmergencyReservePlainDetailPageReqVO pageVO) {
        PageResult<BizEmergencyReservePlainDetailDO> pageResult = emergencyReservePlainDetailService.getEmergencyReservePlainDetailPage(pageVO);
        return success(BizEmergencyReservePlainDetailConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出预案详情 Excel")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-detail:export')")
    @OperateLog(type = EXPORT)
    public void exportEmergencyReservePlainDetailExcel(@Valid BizEmergencyReservePlainDetailExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizEmergencyReservePlainDetailDO> list = emergencyReservePlainDetailService.getEmergencyReservePlainDetailList(exportReqVO);
        // 导出 Excel
        List<BizEmergencyReservePlainDetailExcelVO> datas = BizEmergencyReservePlainDetailConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "预案详情.xls", "数据", BizEmergencyReservePlainDetailExcelVO.class, datas);
    }

}
